// 连接数据库 导出db Schema
const mongoose = require('mongoose')
const db = mongoose.createConnection("mongodb://localhost:27017/tribune", {useNewUrlParser: true})
// 原生 Promise 替换 mongoose 的promise
mongoose.Promise = global.Promise

const Schema = mongoose.Schema

db.on("error", () => {
  console.log("连接数据库失败")
})
db.on("open", () => {
  console.log('blogproject 数据库连接成功');  
})

module.exports = {
  db,
  Schema
}